"""
The schedule models are aimed at automatic timetable preparation for a conference.

It is assumed that the resources are limited and the best possible orderng is
to be chosen for the timetable.

This work is inspired by a recent trip to EuroPython where several interesting talks had been
scheduled together.
"""

from django.db.models import Model, CharField, IntegerField, FloatField, ForeignKey, TimeField

class Constraint(Model):
    """
    Says something about the times either:
       times when something is possible or
       times when something is impossible.
    """
    POSSIBLE = 'P'
    IMPOSSIBLE = 'I'
    KIND=(POSSIBLE, 'Possible'), (IMPOSSIBLE, 'Impossible')
    kind = CharField(max_length=1,choices=KIND)
    description = CharField(max_length=128, blank=True, unique=True)
    
    def __unicode__(self):
        """
        """
        return self.get_kind_display() + self.description

class TimeSlot(Model):
    """
    A start time and duration for a constraint.
    """
    constraint = ForeignKey(Constraint)
    start = TimeField()
    duration = FloatField() # in hours
    description = CharField(max_length=128, blank=True)
    
class Location(Model):
    """
    A location is some place where activities can happen.
    """
    name = CharField(max_length=128, unique=True)
    capacity = IntegerField()
    constraint = ForeignKey(Constraint, null=True, blank=True)
    
    def __unicode__(self):
        """
        """
        return self.name

class Delegate(Model):
    """
    A delegate is an conference attendee including organisers and speakers.
    """
    identifier = CharField(max_length=8, unique=True)
    name = CharField(max_length=128)
    constraint = ForeignKey(Constraint, null=True, blank=True)

    def __unicode__(self):
        """
        """
        return self.name
    
class Activity(Model):
    """
    An activity can be many things... for example: a Talk, a Break or a Keynote etc.
    """
    title = CharField(max_length=120, unique=True)
    extra = CharField(max_length=240, blank=True)
    constraint = ForeignKey(Constraint, null=True, blank=True)

    def __unicode__(self):
        """
        """
        return self.title

class Require(Model):
    """
    A require object is created for each delegate who must be present at an activity.
    kind denotes the delegate contribution.
    """
    SPEAKER = 'S'
    OFFICIAL = 'O'
    KIND = (SPEAKER, 'Speaker'), (OFFICIAL, 'Official')
    kind = CharField(max_length=1, choices=KIND)
    delegate = ForeignKey(Delegate)
    activity = ForeignKey(Activity)

    class Meta:
        """
        """
        unique_together = 'delegate', 'activity'
        
class Desire(Model):
    """
    An desire object is created when a delagate wishes to attend an activity.
    kind denotes the delegate level of interest.
    """
    MUSTSEE = 'M'
    INTERESTED = 'I'
    WHATEVER = 'W'
    KIND=(MUSTSEE, 'Must See'), (INTERESTED, 'Interested'), (WHATEVER,'Whatever..')
    kind = CharField(max_length=1, choices=KIND)
    delegate = ForeignKey(Delegate)
    activity = ForeignKey(Activity)
    
    class Meta:
        """
        """
        unique_together = 'delegate', 'activity'
